package com.sskj.mine;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.text.TextUtils;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;

import com.hjq.toast.ToastUtils;
import com.sskj.common.util.ClickUtil;
import com.sskj.common.util.ImageUtil;
import com.sskj.lib.base.BaseActivity;
import com.sskj.lib.bean.UserData;
import com.sskj.lib.model.room.UserViewModel;
import com.sskj.mine.component.DaggerUserDataComponent;

import javax.inject.Inject;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * @author Hey
 * Create at  2019/05/04
 */
public class ChangeNameActivity extends BaseActivity<ChangeNamePresenter> {

    @BindView(R2.id.name_edt)
    EditText nameEdt;
    @BindView(R2.id.submit_btn)
    Button submitBtn;
    @Inject
    UserViewModel userViewModel;
    private UserData userData;

    @Override
    public int getLayoutId() {
        return R.layout.mine_activity_change_name;
    }

    @Override
    public ChangeNamePresenter getPresenter() {
        return new ChangeNamePresenter();
    }

    @Override
    public void initView() {
        setTitle(getString(R.string.mine_changeNameActivity1));
        DaggerUserDataComponent.create().inject(this);
        userViewModel.getUsers().observe(this, users -> {
            if (users != null && users.size() > 0) {
                userData = users.get(0);
            } else {
                userData = null;
            }
        });
    }

    @Override
    protected void initEvent() {
        ClickUtil.click(submitBtn, () -> {
            if (isEmpty(nameEdt)) {
                ToastUtils.show(getString(R.string.mine_changeNameActivity2));
                return;
            }
            mPresenter.nickName(nameEdt.getText().toString().trim());
        });
    }

    public static void start(Context context) {
        Intent intent = new Intent(context, ChangeNameActivity.class);
        context.startActivity(intent);
    }

    public void updateUi() {
        userViewModel.update();
        finish();
    }

}
